/*
 * @Author: zl '1335450872@qq.com'
 * @Date: 2024-04-06 15:22:43
 * @LastEditors: '陈宗泺' '1335450872@qq.com'
 * @LastEditTime: 2024-05-23 23:49:54
 * @FilePath: \vue\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'

Vue.use(VueRouter)

// 解决导航栏或者底部导航tabBar中的vue-router在3.0版本以上频繁点击菜单报错的问题。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
   {
       path: '/',
       redirect: '/front/home',
   } 
  ,{
    path: '/',
    name: 'Manager',
    component: () => import('../views/Manager.vue'),
    redirect: '/home',  // 重定向到主页
    children: [
      { path: '403', name: 'NoAuth', meta: { name: '无权限' }, component: () => import('../views/manager/403') },
      { path: 'home', name: 'Home', meta: { name: '系统首页' }, component: () => import('../views/manager/Home') },
      { path: 'home/admin', name: 'Admin', meta: { name: '管理员信息' }, component: () => import('../views/manager/Admin') },
      { path: 'home/user', name: 'User', meta: { name: '用户信息' }, component: () => import('../views/manager/User') },
      { path: 'home/adminPerson', name: 'AdminPerson', meta: { name: '个人信息' }, component: () => import('../views/manager/AdminPerson') },
      { path: 'home/password', name: 'Password', meta: { name: '修改密码' }, component: () => import('../views/manager/Password') },
      { path: 'home/notice', name: 'Notice', meta: { name: '公告信息' }, component: () => import('../views/manager/Notice') },
      { path: 'home/repair', name: 'Repair', meta: { name: '接单信息' }, component: () => import('../views/manager/Repair') },
      { path: 'home/repairer', name: 'Repairer', meta: { name: '维修人员信息' }, component: () => import('../views/manager/Repairer') },
      { path: 'home/Carousel', name: 'Carousel', meta: { name: '活动信息' }, component: () => import('../views/manager/Carousel.vue') },
    ]
},
  {
    path: '/front',
    name: 'Front',
    component: () => import('../views/Front.vue'),
    children: [
      { path: 'home', name: 'Home', meta: { name: '系统首页' }, component: () => import('../views/front/Home') },
      { path: 'person', name: 'Person', meta: { name: '个人信息' }, component: () => import('../views/front/Person') },
      { path: 'repairs', name: 'Repairs', meta: { name: '报修中心' }, component: () => import('../views/front/Repairs') },
      { path: 'association', name: 'About', meta: { name: '关于我们' }, component: () => import('../views/front/Association') },
      { path: 'ucenter', name: 'Ucenter', meta: { name: '用户中心' }, component: () => import('../views/front/Ucenter') },
      {
        path: 'repair-list',
        name: 'MyRepairList',
        component: () => import('../views/repair/MyRepairList.vue'),
        meta: { requireAuth: true }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/adminLogin',
    name: 'AdminLogin',
    component: () => import('../views/AdminLogin.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },

  { path: '/repair/my', name: 'MyRepairList', component: () => import('../views/repair/MyRepairList.vue') },
  {
    path: '/repair/workbench',
    name: 'RepairWorkbench',
    component: () => import('../views/repair/RepairWorkbench.vue'),
    meta: { requiresAuth: true, role: 'repair' }
  },
  { path: '*', name: 'NotFound', meta: { name: '无法访问' }, component: () => import('../views/404.vue') },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 注：不需要前台的项目，可以注释掉该路由守卫
// 路由守卫
// router.beforeEach((to ,from, next) => {
//   let user = JSON.parse(localStorage.getItem("xm-user") || '{}');
//   if (to.path === '/') {
//     if (user.role) {
//       if (user.role === 'USER') {
//         next('/front/home')
//       } else {
//         next('/home')
//       }
//     } else {
//       next('/login')
//     }
//   } else {
//     next()
//   }
// })

export default router
